package com.example.schooljava.common;

import com.example.schooljava.exception.AuthHandlerInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * token 拦截器配置
 *
 * @author: LDH
 * @date: 2022年06月17日 15:36
 */
@Configuration
public class AuthWebMvcConfigurer implements WebMvcConfigurer {
    @Autowired
    AuthHandlerInterceptor authHandlerInterceptor;

    /**
     * 给除了 /login 的接口都配置拦截器,拦截转向到 authHandlerInterceptor
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(authHandlerInterceptor)
                .addPathPatterns("/school/**")
                .excludePathPatterns(
                        "/doc.html",
                        "/school/**/login",
                        "/school/**/register",
                        "/school/teacher/router"
                );
    }
}
